package com.snack.shop.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.snack.shop.common.Result;
import com.snack.shop.dto.ProductStatsDTO;
import com.snack.shop.service.StatsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 统计接口
 */
@Tag(name = "统计管理")
@RestController
@RequestMapping("/stats")
@RequiredArgsConstructor
public class StatsController {

    private final StatsService statsService;

    @Operation(summary = "商品统计数据")
    @SaCheckRole("merchant")
    @GetMapping("/product")
    public Result<ProductStatsDTO> getProductStats(
            @Parameter(description = "库存预警阈值（默认10）")
            @RequestParam(required = false) Integer stockThreshold
    ) {
        ProductStatsDTO data = statsService.getProductStats(stockThreshold);
        return Result.success(data);
    }
}
